package net.hctek.identity.action;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;

import net.hctek.identity.bean.Navs;
import net.hctek.identity.bean.User;
import net.hctek.identity.service.IdentityServiceI;
import net.hctek.identity.util.ResponseJsonUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class NavsAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	@Autowired
	private IdentityServiceI identityService;
	
	public String showNavs(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			List<Navs> navsAll= identityService.getNavsAll();
			JSONArray json = new JSONArray();
			 for(Navs n : navsAll){
	                JSONObject jo = new JSONObject();
	                jo.put("title",n.getNavsTitle());
	                jo.put("icon", n.getNavsIcon());
	                jo.put("href",n.getNavsHref());
	                jo.put("spread",n.getNavsSpread());
	                json.add(jo);
	            }
			System.out.println(json.toString());
			ResponseJsonUtils.json(response, json);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
}
